package com.jrj.action;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapExecutor;
import com.jrj.domain.Csdn;
import com.jrj.service.CsdnService;
import com.opensymphony.xwork2.ActionSupport;

/**
 *@author zhiming.li
 *@version createTime：2011-12-22 上午09:04:39
 */
public class CsdnAction extends ActionSupport  {
	
	@Autowired
	private CsdnService csdnService;
	
	
	//aaa
	public String execute() throws Exception {
		
		
		
		double start = System.currentTimeMillis();
		System.out.println("开始时间---->"+start);
		String fileName = "G:\\360Downloads\\csdn\\www.csdn.net.sql"; 
		List<Csdn> list = new ArrayList<Csdn>();
		try {
			FileReader fi = new FileReader(fileName);
			BufferedReader   br=new   BufferedReader(fi); 
			String s =null;
			try {
				int i  = 0;
				while((s=br.readLine())!=   null){
					
				   String arr[] = s.split("#");
				   Csdn cs = new Csdn();
				   cs.setUserName(arr[0]);
				   cs.setPassWord(arr[1]);
				   cs.setEmail(arr[2]);
				//   csdnService.addCsdn(cs);
				   list.add(cs);
				   i++;
				   if(i==500){
					  csdnService.addCsdn1(list);
					   list.clear();
					  
					   i=0;
				   }
				 }
				
//				for (int i = 0; i < 100; i++) {
//					 Csdn cs = new Csdn();
//					 cs.setUserName("111");
//					 cs.setPassWord("111");
//					 cs.setEmail("111");
//					 list.add(cs);
//					// System.out.println(csdnService);
//				}
//				double s1 = System.currentTimeMillis();
//				 csdnService.addCsdn1(list);
//				double s2 = System.currentTimeMillis();
//				System.out.println(s2-s1);
			} catch (IOException e) {
				e.printStackTrace();
			} 
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		double end = System.currentTimeMillis();
		System.out.println("结束时间---->"+end);
		double time = end -start;
		
		System.out.println(time);

        
		return "addCsdn";
	}
	
	
	
	
	
	
//	public void inser(List<Csdn> list){
//		try {
//			
//		System.out.println(this.getSqlMapClientTemplate());
//		final List<Csdn> list1 = list;
//		 this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {  
//	            public Object doInSqlMapClient(SqlMapExecutor executor)  
//	                    throws SQLException {  
//	            	//executor.startBatch();  
//	            	System.out.println(executor);
//	                for (Csdn csdn : list1) { 
//	                	System.out.println(csdn.getEmail());
//	                  //  executor.insert("com.jrj.dao.CsdnDao.addCsdn", csdn);//此处可以是update、delete  
//	                }  
//	                //executor.executeBatch();  
//	                return null;  
//	            }  
//	        });  
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
	
	
	
	private  String getCsdn(){
		String fileName = "G:\\csdn\\www.csdn.net.sql"; 
		double start = System.currentTimeMillis();
		try {
			FileReader fi = new FileReader(fileName);
			BufferedReader   br=new   BufferedReader(fi); 
			String s =null;
			try {
				int i  = 10;
				while((s=br.readLine())!=   null){ 
				   String arr[] = s.split("#");
				   Csdn cs = new Csdn();
				   cs.setUserName(arr[1]);
				   cs.setPassWord(arr[2]);
				   cs.setEmail(arr[3]);
				   csdnService.addCsdn(cs);
				   i++;
				   if(i==20){
					   break;
				   }
				 }
			} catch (IOException e) {
				e.printStackTrace();
			} 
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		double end = System.currentTimeMillis();
		double time = end - start;
		System.out.println(time);
		return "";
	}
	
}
